package com.lagou;

import com.lagou.bean.ConsumerComponent;
import org.apache.dubbo.common.threadpool.support.fixed.FixedThreadPool;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DubboMonitorConsumerMain {

    private static ExecutorService threadPool = Executors.newFixedThreadPool(7);

    public static void main(String[] args) throws IOException {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        applicationContext.start();
        ConsumerComponent service = applicationContext.getBean(ConsumerComponent.class);
        while (true) {
            System.in.read();
            for (int i = 0; i < 2000; i++) {
                threadPool.submit(new Runnable() {
                    @Override
                    public void run() {
                        service.methodA();
                        service.methodB();
                        service.methodC();
                    }
                });
            }
        }
    }


    @Configuration
    @EnableDubbo
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(value = "com.lagou.bean")
    static class ConsumerConfiguration {

    }
}
